﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace SemanticEx
{
	public static class NumberExtensions
	{
		public static bool IsInteger(this double @this)
		{
			return @this == (int)@this;
		}

		/// <summary>Split an integer into digits.</summary>
		public static IEnumerable<int> SplitDigits(this int @this)
		{
			List<int> values = new List<int>();
			int numDigits = (int)Math.Log10(@this);
			for (int index = numDigits; index >= 0; index--)
			{
				values.Add(@this / (int)Math.Pow(10, index));
				@this -= values.Last() * (int)Math.Pow(10, index);
			}
			if (!values.Any())
			{
				values.Add(0);
			}
			return values.Reverse<int>();
		}
	}
}